import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

//store存储数据
export default new Vuex.Store({
  state: {
    token: '',
    mobile: '',
    name: '',
    areaCode: '',
    uid: '',
    header: '',
    selectBank:'',//提现选择的银行卡
    maintain: false,
    downloadUrl: '',//下载app链接
    showCustomerNotice: false,//显示新老用户迁移通知
    loading: false, /*是否显示加载动画*/
    gologin: false,//http公共跳转登录页判断
    chose_coupons : [], //选择的优惠券
    rent_num : 1, //租用数量
    buy_math_power : false , //是否购买算力宝
    payType : 'RRM_CASH', // 支付方式
    reloadHeader : false
  },
  mutations: {
    reloadHeader(state, mes) {
      state.reloadHeader = mes;
    },
    chose_coupons(state, mes) {
      state.chose_coupons = JSON.stringify(mes);
    },
    rent_num(state, mes) {
      state.rent_num = mes;
    },
    buy_math_power(state, mes) {
      state.buy_math_power = mes;
    },
    payType(state, mes) {
      state.payType = mes;
    },
    selectBank(state, mes) {
      state.selectBank = JSON.stringify(mes);
    },
    maintain(state, mes) {
      state.maintain = mes;
    },
    downloadUrl(state, mes) {
      state.downloadUrl = mes;
    },
    showCustomerNotice(state, mes) {
      state.showCustomerNotice = mes;
    },
    gologin(state, mes) {
      state.gologin = mes;
    },
    token(state, mes) {
      state.token = mes;
      localStorage.setItem('token', mes);
    },
    name(state, mes) {
      state.name = mes;
      localStorage.setItem('name', mes);
    },
    mobile(state, mes) {
      state.mobile = mes;
      localStorage.setItem('mobile', mes);
    },
    areaCode(state, mes) {
      state.areaCode = mes;
      localStorage.setItem('areaCode', mes);
    },
    uid(state, mes) {
      state.uid = mes;
      localStorage.setItem('uid', mes);
    },
    header(state, mes) {
      state.mobile = mes;
      localStorage.setItem('header', mes);
    },
    storageRemove(state, name) { //删除缓存(退出登录等操作)
      if (name == 'all') {
        //调用方法（删除用户所有数据所有）：store.commit('storageRemove','all');
        localStorage.clear();
        state.token = '';
        state.mobile = '';
        state.uid = '';
        state.header = '';
      }
    },
    isLoading(state, mes) {
      state.loading = mes;
    }
  }
})
